package com.sino.operation.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;


import com.sino.operation.dto.inner.other.Table;
import com.sino.operation.entity.BizCityServiceCode;
import com.sino.operation.entity.UserTest;
import com.sino.operation.mapper.BizCityServiceCodeMapper;
import com.sino.operation.param.out.EscReceiveByCounterToAccount;

import com.sino.operation.peripheral.esc.request.core.EscCoreParam;
import com.sino.operation.peripheral.esc.request.core.body.EscBodyCore4020;
import com.sino.operation.peripheral.esc.request.manage.param.Manage_1005_Param;
import com.sino.operation.peripheral.esc.response.EscResponseDto;
import com.sino.operation.service.business.AccountStartTest;
import com.sino.operation.service.business.inter.CoreTestService;

import com.sino.operation.service.business.inter.StartService;
import com.sino.operation.util.EscResTest;

import com.sino.operation.peripheral.esc.core.vo.Core_2110_VO;
import com.sino.operation.peripheral.esc.core.vo.Core_2117_VO;
import com.sino.operation.peripheral.esc.core.vo.Core_2157_VO;
import com.sino.operation.peripheral.esc.core.vo.Core_2158_VO;
import com.sino.operation.commons.response.CenterResponseEntity;
import com.sino.operation.vo.current.FieldInformation;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import java.lang.reflect.Field;
import java.util.*;


/**
 * 活期存款账户
 *
 * @author Administrator
 * date 2021/9/15 0015 22:39
 */
@Slf4j
@RestController
@RequestMapping("account")
@Api(value = "存款账户",tags = "开变销")
@Validated
public class CurrentAccountController {


    @Autowired
    private StringRedisTemplate redisTemplate;


    @Autowired
    private CoreTestService coreTestService;

    @Autowired
    private StartService startService;

    @Autowired
    private AccountStartTest accountStartTest;

    @Autowired(required = false)
    private BizCityServiceCodeMapper BizCityServiceCodeMapper;

    @PostMapping("startCurrentAccount")
    @ApiOperation(value = "单位开户交易发起接口")
    //@StartJudgment(value = "发起流程自动校验规则")
    public EscResponseDto startCurrentOpen(@RequestBody @Valid EscReceiveByCounterToAccount escReceiveByCounterToAccount) throws Exception {
        CenterResponseEntity<Object> build = CenterResponseEntity.build(Object.class);
        String s = startService.startTrans(escReceiveByCounterToAccount);
        HashMap<Object, Object> map = new HashMap<>(16);
        map.put("JOURNAL_NO",s);
        build.setData(map);
        EscResponseDto escReponse = EscResTest.getEscReponse();
        escReponse.getEscResBody().setCenterResponseEntity(build);
        return escReponse;
    }

    @PostMapping("startChangeAccount")
    @ApiOperation(value = "单位账户维护信息交易发起接口")
    //@StartJudgment(value = "发起流程自动校验规则")
    public EscResponseDto startChangeAccount(@RequestBody @Valid EscReceiveByCounterToAccount escReceiveByCounterToAccount)throws Exception{
        CenterResponseEntity<Object> build = CenterResponseEntity.build(Object.class);
        String s = startService.startTrans(escReceiveByCounterToAccount);
        HashMap<Object, Object> map = new HashMap<>(16);
        map.put("JOURNAL_NO",s);
        build.setData(map);
        EscResponseDto escReponse = EscResTest.getEscReponse();
        escReponse.getEscResBody().setCenterResponseEntity(build);
        return escReponse;

    }

    @PostMapping("startCloseAccount")
    @ApiOperation(value = "单位销户交易发起接口")
    //@StartJudgment(value = "发起流程自动校验规则")
    public EscResponseDto startCloseAccount(@RequestBody @Valid EscReceiveByCounterToAccount escReceiveByCounterToAccount)throws Exception{
        CenterResponseEntity<Object> build = CenterResponseEntity.build(Object.class);
        String s = startService.startTrans(escReceiveByCounterToAccount);
        HashMap<Object, Object> map = new HashMap<>(16);
        map.put("JOURNAL_NO",s);
        build.setData(map);
        EscResponseDto escReponse = EscResTest.getEscReponse();
        escReponse.getEscResBody().setCenterResponseEntity(build);
        return escReponse;
    }


    @GetMapping("chargeTest")
    @ApiOperation(value = "开户记账测试")
    public EscResponseDto startChangeAccount( String  journalNo) throws Exception {
        CenterResponseEntity<Object> build = CenterResponseEntity.build(Object.class);
        startService.chargeTest(journalNo);
        EscResponseDto escReponse = EscResTest.getEscReponse();
        escReponse.getEscResBody().setCenterResponseEntity(build);
        return escReponse;
    }

    @GetMapping("mapTest")
    @ApiOperation(value = "测试")
    //@StartJudgment(value = "发起流程自动校验规则")
    public Object mapTest() throws Exception {
        Class<Manage_1005_Param> manage1005ParamClass = Manage_1005_Param.class;
        Map<String, Object> map = new HashMap<>(16);
        Field[] declaredFields = manage1005ParamClass.getDeclaredFields();
        for (Field field : declaredFields) {
            JsonProperty annotation = field.getAnnotation(JsonProperty.class);
            String value = annotation.value();
            ApiModelProperty annotation1 = field.getAnnotation(ApiModelProperty.class);
            String name = annotation1.name();
            map.put(name, value);
        }
        return map;

    }

    @Test
    public void setTest() throws Exception {
        System.out.println(new Manage_1005_Param());
    }

    @Test
    public void listTest() throws Exception{
        EscBodyCore4020 escBodyCore4020 = new EscBodyCore4020();
        EscCoreParam<EscBodyCore4020> objectEscCoreParam = new EscCoreParam<>();
        objectEscCoreParam.setEscBodyCore(escBodyCore4020);
        System.out.println(new ObjectMapper().writeValueAsString(objectEscCoreParam));
    }

    @GetMapping("/test11")
    public Object test111() throws JsonProcessingException {
        Map<String, Map<String, Object>> map = new HashMap<>(16);
        Map<String, Object> map1 = new HashMap<>(16);
        map1.put("chinese","基本信息");
        Map<String, Map<String,Object>> map2 = new HashMap<>(16);
        Map<String, Object> map3 = new HashMap<>(16);
        Map<String, Object> map4 = new HashMap<>(16);
        map4.put("value","3333");
        map4.put("mark","1");
        map4.put("cn","账户");
        map3.put("value","2222");
        map3.put("mark","0");
        map3.put("cn","币种");
        map2.put("cyno",map3);
        map2.put("acco",map4);
        map1.put("field",map2);
        Map<String,Object> field = (Map)map1.get("field");
        Map<String, Object> map5=(Map)field.get("cyno");
        map5.get("value");
        return map1;

    }

    @Test
    public void json() throws JsonProcessingException {
        UserTest value = new UserTest();
        value.setId("111");
        String string = new ObjectMapper().writeValueAsString(value);
        UserTest userTest = new UserTest();
        try {
            userTest = new ObjectMapper().readValue(string, UserTest.class);

        }catch (Exception e){
            System.out.println(e.getMessage());
        }
        System.out.println(new ObjectMapper().writeValueAsString(value));

    }



    @Test
    public void jsonStr()throws Exception{
        ArrayList<Table> tables = new ArrayList<>();
        Table table = new Table();
        table.setEnglishName("YLYJR");
        table.setChineseName("预留印鉴人信息");
        ArrayList<List<FieldInformation>> lists = new ArrayList<>();

        List<FieldInformation> fieldInformations1 = new ArrayList<>();
        List<FieldInformation> fieldInformations2 = new ArrayList<>();

        FieldInformation fieldInformation1 = new FieldInformation();
        FieldInformation fieldInformation2 = new FieldInformation();
        fieldInformation1.setEnglishName("YLXM");
        fieldInformation1.setChineseName("预留姓名");
        fieldInformation1.setFieldOldValue("张三");
        fieldInformation1.setFieldValue("张三");
        fieldInformation1.setIsChange("0");
        fieldInformation1.setShowRemark("1");
        fieldInformation1.setMarkNum("0");

        fieldInformation2.setEnglishName("YLHM");
        fieldInformation2.setChineseName("预留号码");
        fieldInformation2.setFieldOldValue("125649785");
        fieldInformation2.setFieldValue("16565625");
        fieldInformation2.setIsChange("1");
        fieldInformation2.setShowRemark("2");
        fieldInformation2.setMarkNum("1");
        fieldInformations1.add(fieldInformation1);
        fieldInformations1.add(fieldInformation2);

        FieldInformation fieldInformation3 = new FieldInformation();
        FieldInformation fieldInformation4 = new FieldInformation();

        fieldInformation3.setEnglishName("YLXM");
        fieldInformation3.setChineseName("预留姓名");
        fieldInformation3.setFieldOldValue("李四");
        fieldInformation3.setFieldValue("李四");
        fieldInformation3.setIsChange("0");
        fieldInformation3.setShowRemark("1");
        fieldInformation3.setMarkNum("0");

        fieldInformation4.setEnglishName("YLHM");
        fieldInformation4.setChineseName("预留号码");
        fieldInformation4.setFieldOldValue("456987989");
        fieldInformation4.setFieldValue("798989");
        fieldInformation4.setIsChange("1");
        fieldInformation4.setShowRemark("2");
        fieldInformation4.setMarkNum("1");

        fieldInformations2.add(fieldInformation3);
        fieldInformations2.add(fieldInformation4);

        lists.add(fieldInformations1);
        lists.add(fieldInformations2);
        table.setFieldList(lists);
        tables.add(table);
        System.out.println(new ObjectMapper().writeValueAsString(tables));
    }

    @PostMapping("test")
    @ApiOperation(value = "测试日志接口")
    public void test(){
        System.out.println("成功了！！");
    }

/*    @GetMapping("reflect")
    public Object reflect(String id) throws Exception {
        if ("1".equals(id)){
            User user = new User();
            user.setId("222");
            user.setUserName("张三");
            user.setPassword("123456");
            return user;
        }else if ("2".equals(id)){
            User user = new User();
            user.setId("333");
            user.setUserName("李四");
            user.setPassword("aaaaaa");
            String s = JSONUtil.toJsonStr(user);
            return s;
        }else{
            User user = new User();
            user.setId("444");
            user.setUserName("王五");
            user.setPassword("bbbbbb");
            String s = JSONUtil.toJsonStr(user);
            JSON parse = JSONUtil.parse(s);
            return parse;
        }
    }*/

    @GetMapping("coreTest")
    public CenterResponseEntity coreTest(String id){
        if ("1".equals(id)){
            Core_2110_VO core_2110_vo = coreTestService.startCore2110();
            return CenterResponseEntity.build(Core_2110_VO.class).setData(core_2110_vo);
        }else if ("2".equals(id)){
            Core_2117_VO core_2117_vo = coreTestService.startCore2117();
            return CenterResponseEntity.build(Core_2117_VO.class).setData(core_2117_vo);
        }else if ("3".equals(id)){
            Core_2157_VO core_2157_vo = coreTestService.startCore2157();
            return CenterResponseEntity.build(Core_2157_VO.class).setData(core_2157_vo);
        }else if ("4".equals(id)){
            Core_2158_VO core_2158_vo = coreTestService.startCore2158();
            return CenterResponseEntity.build(Core_2158_VO.class).setData(core_2158_vo);
        }
        return CenterResponseEntity.build();
    }

    public static void main(String[] args) throws Exception {
        FileReader f1 = new FileReader(new File("D:\\eg.txt"));
        FileReader f2 = new FileReader(new File("D:\\cn.txt"));
        FileReader f3 = new FileReader(new File("D:\\type.txt"));
        BufferedReader b1 = new BufferedReader(f1);
        BufferedReader b2 = new BufferedReader(f2);
        BufferedReader b3 = new BufferedReader(f3);
        ArrayList<String> l1 = new ArrayList<>();
        ArrayList<String> l2 = new ArrayList<>();
        ArrayList<String> l3 = new ArrayList<>();
        String line=null;
        while ((line=b1.readLine())!=null){
            l1.add(line);
        }
        f1.close();
        b1.close();

        while ((line=b2.readLine())!=null){
            l2.add(line);
        }
        f2.close();
        b2.close();

        while ((line=b3.readLine())!=null){
            l3.add(line);
        }
        f3.close();
        b3.close();
        System.out.println(l1.size()+":"+l2.size()+":"+l3.size());
        int size = l1.size();
        for (int i = 0; i < size; i++) {
            String s = l1.get(i);
            String s1 = l2.get(i);
            String s2 = l3.get(i);
            char[] chars = s.toCharArray();
            int length = chars.length;
            StringBuilder builder = new StringBuilder();
            boolean test=false;
            for (int j = 0; j < length; j++) {
                int value=(int)chars[j];
                if (j==0){
                    builder.append(chars[j]);
                }else {
                    if (test){
                        if (chars[j]>=97&&chars[j]<=122){
                            value=value-32;
                            char valueR=(char)value;
                            builder.append(valueR);
                            test=false;
                        }else {
                            builder.append(chars[j]);
                            test=false;
                        }
                    }else {
                        if (chars[j]!='_'){
                            builder.append(chars[j]);
                            test=false;
                        }
                    }
                    if (chars[j]=='_'){
                        test=true;
                    }

                }
            }
            String sN = builder.toString();
            System.out.println("@JsonProperty(\""+s+"\")\n"+"@ApiModelProperty(name = \""+s+"\",value = \""+s1+"\")\n"+"private "+s2+" "+sN+";\n");
        }
    }
}
